package org.ank.food;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

public class SaveProfileActivity extends Activity{
	
	Button backButton,saveButton,cancelButton;
	TextView title, info;
	ProfileManager profileManager;

	
	@Override
	public void onCreate(Bundle b){
		super.onCreate(b);
		setContentView(R.layout.save_profile_activity);
		

		saveButton = (Button)findViewById(R.id.save_profile_save_button);
		backButton = (Button)findViewById(R.id.save_profile_back_button);
		cancelButton = (Button)findViewById(R.id.save_profile_cancel_button);
		info = (TextView)findViewById(R.id.save_profile_info_textview);
		info.setText(ProfileManager.getInstance(getApplicationContext()).getNewProfileInfo());
		title = (TextView)findViewById(R.id.save_profile_title);
		
		profileManager = ProfileManager.getInstance(getApplicationContext());
		if (profileManager.getProfileMode() == ProfileManager.PROFILE_MODE_EDIT){
			title.setText(getString(R.string.save_profile_save_changes));
		}
		
		saveButton.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				ProfileManager.getInstance(getApplicationContext()).saveNewOrUpdateProfile();
				Intent intent = new Intent();
//        		intent.setClass(getApplicationContext(), EatenTodayActivity.class);
				intent.setClass(getApplicationContext(), ProfileChooseActivity.class);
        		startActivity(intent);
        		finish();
			}
		});
		backButton.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				Intent intent = new Intent();
        		intent.setClass(getApplicationContext(), PhysicalActivityActivity.class);
        		intent.putExtra("caller", PhysicalActivityActivity.ALPHA_VERSION_SAVE_ACTIVITY);//only for alpha
        		startActivity(intent);
        		finish();
			}
		});
		cancelButton.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				AlertDialog.Builder builder = new AlertDialog.Builder(SaveProfileActivity.this);
//				builder.setMessage(getString(R.string.profile_create_alert_dialog_message));
				builder.setNegativeButton(R.string.profile_create_alert_dialog_negative_button_text, 
						new DialogInterface.OnClickListener(){
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
							}
						});
				builder.setPositiveButton(R.string.profile_create_alert_dialog_positive_button_text, 
						new DialogInterface.OnClickListener(){
						@Override
						public void onClick(DialogInterface dialog,	int which) {
							Intent intent = new Intent();
			        		intent.setClass(getApplicationContext(), ProfileChooseActivity.class);
			        		startActivity(intent);
			        		finish();
						}
					});
//				builder.setTitle(R.string.profile_create_alert_dialog_title);
				builder.show();
			}
			
		});
		
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Intent intent = new Intent();
			intent.setClass(getApplicationContext(), PhysicalActivityActivity.class);
    		intent.putExtra("caller", PhysicalActivityActivity.ALPHA_VERSION_SAVE_ACTIVITY);//only for alpha
			startActivity(intent);
			finish();
			return true;
		}
	    return super.onKeyDown(keyCode, event);
	}

}